package com.sskj.gocoinapp.presenter;

import android.view.View;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.HttpHeaders;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.SPUtil;
import com.sskj.common.util.ToastUtil;
import com.sskj.gocoinapp.bean.LoginBean;
import com.sskj.gocoinapp.bean.MiningQPBean;
import com.sskj.gocoinapp.bean.MiningTips;
import com.sskj.gocoinapp.http.HttpConfig;
import com.sskj.gocoinapp.ui.activity.MiningActivity;
import com.sskj.lib.SPConfig;
import com.sskj.lib.http.JsonCallBack;

import java.util.ArrayList;
import java.util.List;

public class MiningPresenter extends BasePresenter<MiningActivity> {

    /**
     * 获取气泡
     */
    public void getMiningNum() {
        httpService.getMiningNum()
                .execute(new JsonCallBack<HttpData<List<MiningQPBean>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<List<MiningQPBean>>> response) {
                        HttpData<List<MiningQPBean>> httpData = response.body();
                        List<MiningQPBean> listQp = new ArrayList<>();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            for (int i = 0; i < httpData.getData().size(); i++) {
                                MiningQPBean qpUsdtBean = new MiningQPBean(httpData.getData().get(i));
                                qpUsdtBean.setUsdtOrGct(true);
                                listQp.add(qpUsdtBean);
                                MiningQPBean qpGctBean = new MiningQPBean(httpData.getData().get(i));
                                qpGctBean.setUsdtOrGct(false);
                                listQp.add(qpGctBean);
                            }
                            mView.updateQp(listQp);
                        }
                    }
                });
    }

    /**
     * 收取气泡
     */
    public void successQp(View view, String type, String pid) {
        httpService.successQp(type, pid)
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData<List<MiningQPBean>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.removeWaterView(view);
                            getIcome(type.equals("gct") ? 1 : 2);
                        } else if (httpData.getStatus() == 400) {  // 合约界面
                            mView.showDialog(httpData.getMsg(), httpData.getStatus());
                        } else if (httpData.getStatus() == 500) {  // 邀请好友界面
                            mView.showDialog(httpData.getMsg(), httpData.getStatus());
                        } else if (httpData.getStatus() == 303 || httpData.getStatus() == 301 || httpData.getStatus() == 302) {  // 充值界面
                            mView.showDialog(httpData.getMsg(), httpData.getStatus());
                        } else {
                            ToastUtil.showShort(httpData.getMsg());
                        }

                    }
                });
    }

    /**
     * 获取累计收益
     */
    public void getIcome(int type) { // 0 代表都出现动画效果  1 GCT  2 USDT
        httpService.getIcome()
                .execute(new JsonCallBack<HttpData<MiningQPBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<MiningQPBean>> response) {
                        HttpData<MiningQPBean> httpData = response.body();
                        mView.updateUi(httpData.getData(), type);
                    }
                });
    }

    /**
     * 原力说明
     */
    public void getNotice() {
        httpService.getMiningTips()
                .execute(new JsonCallBack<HttpData<MiningTips>>() {
                    @Override
                    public void onSuccess(Response<HttpData<MiningTips>> response) {
                        HttpData<MiningTips> httpData = response.body();
                        mView.showNotice(httpData.getData().getStore_force());
                    }
                });
    }


}
